export default function register(lf) {
  lf.register('startNode', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        const { model } = this.props
        const { stroke } = model.getNodeStyle()
        return h(
          'svg',
          {
            x: 15,
            y: 13,
            width: 40,
            height: 40,
            viewBox: '0 0 1024 1024'
          },
          [
            h(
              'path',
              {
                fill: '#027DB4',
                d: 'M512 64C264.58 64 64 264.58 64 512s200.58 448 448 448 448-200.58 448-448S759.42 64 512 64z m265.87 713.87a374.62 374.62 0 1 1 80.61-119.54 374.59 374.59 0 0 1-80.61 119.54z'
              }
            ),
            h(
              'path',
              {
                fill: '#027DB4',
                d: 'M696.93 500l-255-217a18.82 18.82 0 0 0-12.53-4.73c-9.47 0-18.41 6.58-18.41 16.66V729c0 10 8.94 16.66 18.41 16.66a18.43 18.43 0 0 0 12.48-4.66l255-217a15.62 15.62 0 0 0 0.05-24z'
              }
            )


          ]

        )
      }
      getShape() {
        const { model } = this.props
        const { width, height, x, y, points } = model
        const { fill, fillOpacity, strokeWidth, stroke, strokeOpacity, } = model.getNodeStyle()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        const pointsPath = points.map(point => point.join(',')).join(' ')
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'polygon',
              {
                points: pointsPath,
                fill,
                stroke,
                strokeWidth,
                strokeOpacity,
                fillOpacity
              }
            ),
            this.getIconShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        data.text = {
          value: (data.text && data.text.value) || '开始节点',
          x: data.x,
          y: data.y + 50
        }
        super(data, graphModel)
      }
      initNodeData(data) {
        super.initNodeData(data)
        const lenght = 35
        this.points = [
          [lenght, 0],
          [lenght * 2, lenght],
          [lenght, lenght * 2],
          [0, lenght]
        ]
      }
      // 自定义锚点样式
      getAnchorStyle() {
        const style = super.getAnchorStyle();
        style.hover.r = 8;
        style.hover.fill = "rgb(24, 125, 255)";
        style.hover.stroke = "rgb(24, 125, 255)";
        return style;
      }
    }
    return {
      view: Node,
      model: Model
    }
  })
}
